<?php
/**订单管理*/
namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Order extends Model
{
    //关联订单表
    protected $table='mzj_orders';
    //显示所有订单
    protected function OrderList($id)
    {
        $res = DB::table('orders')->where('orders_user_id',$id)->get();
        return $res;
    }
    //显示已完成订单
    protected function end_orderList($id){
        $res = DB::table('orders')->where('orders_user_id',$id)
            ->where('orders_status','5')
            ->LeftJoin('order_details','order_details.details_order_id','=','orders.id')
            ->LeftJoin('fitment_details','fitment_details.details_id','=','order_details.details_fitment_id')
            ->select('orders.orders_orderNo','orders.orders_amount','order_details.details_orderNo','fitment_details.details_name','fitment_details.details_length','fitment_details.details_width','fitment_details.details_height','fitment_details.details_number')
            ->get();
        return $res;
    }
    //已支付订单
    protected function pay_orderList($id){
        $res = DB::table('orders')->where('orders_user_id',$id)
            ->where('orders_status','>',0)
            ->where('orders_status','<',5)
            ->LeftJoin('order_details','order_details.details_order_id','=','orders.id')
            ->LeftJoin('fitment_details','fitment_details.details_id','=','order_details.details_fitment_id')
            ->select('orders.orders_orderNo','orders.orders_amount','order_details.details_orderNo','fitment_details.details_name','fitment_details.details_length','fitment_details.details_width','fitment_details.details_height','fitment_details.details_number')
            ->get();
        return $res;
    }
    //未支付订单
    protected function notPay_orderList($id){
        $res = DB::table('orders')->where('orders_user_id',$id)
            ->where('orders_status','=',0)
            ->LeftJoin('order_details','order_details.details_order_id','=','orders.id')
            ->LeftJoin('fitment_details','fitment_details.details_id','=','order_details.details_fitment_id')
            ->select('orders.orders_orderNo','orders.orders_amount','order_details.details_orderNo','fitment_details.details_name','fitment_details.details_length','fitment_details.details_width','fitment_details.details_height','fitment_details.details_number')
            ->get();
        return $res;
    }
    //订单详情
    protected function orderDetail($order_id)
    {
        $res = DB::table('orders')->where('orders.id',$order_id)
            ->LeftJoin('order_details','order_details.details_order_id','=','orders.id')
            ->LeftJoin('fitment_details','fitment_details.details_id','=','order_details.details_fitment_id')
            ->LeftJoin('address','address.addr_id','=','orders.orders_addr_id')
            ->select('order_details.details_orderNo',
                'order_details.created_at',
                'order_details.details_fitment_number',
                'order_details.details_fitment_start',
                'order_details.details_fitment_end',
                'order_details.details_rent_type',
                'orders.orders_status',
                'orders.updated_at',
                'orders.orders_count_bond',
                'orders.orders_quota',
                'orders.orders_amount',
                'fitment_details.details_name',
                'fitment_details.details_length',
                'fitment_details.details_width',
                'fitment_details.details_height',
                'fitment_details.details_bond',
                'fitment_details.details_fixprice',
                'address.*')
            ->get();
        return $res;
    }
}
